package com.newcapec.modules.health.controller;

import com.newcapec.common.utils.PageUtils;
import com.newcapec.common.utils.R;
import com.newcapec.modules.health.entity.StudentEntity;
import com.newcapec.modules.health.service.StudentService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

/**
 * 学生信息
 *
 * @author fujun
 * @email fujun@newcapec.com
 * @date 2021-12-14 09:23:37
 */
@RestController
@RequestMapping("health/student")
public class StudentController {
    @Autowired
    private StudentService studentService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @RequiresPermissions("health:student:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = studentService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @RequiresPermissions("health:student:info")
    public R info(@PathVariable("id") Long id){
		StudentEntity student = studentService.getById(id);

        return R.ok().put("student", student);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @RequiresPermissions("health:student:save")
    public R save(@RequestBody StudentEntity student){
		studentService.add(student);

        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    @RequiresPermissions("health:student:update")
    public R update(@RequestBody StudentEntity student){
		studentService.updateById(student);

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    @RequiresPermissions("health:student:delete")
    public R delete(Long[] ids){
		studentService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }
}
